<?php


namespace app\index\model;


use think\Model;

class Paypal extends Model
{
    public static function getPaypalInfo($group){
        $PaypalClass=new self();
        $data=$PaypalClass
            ->where('del_flag',0)
            ->where('group_id',$group)
            ->field('id,client_id,secret,token,expires_in,last_get_time,invoicer_surname,invoicer_given_name,address_line_1,address_line_2,admin_area_2,admin_area_1,postal_code,country_code,email_address,phones,phone_code')
            ->find();
        if(empty($data)){
            trace('paypal 读取数据失败 '.$group,'error');
            return ['status'=>false,'result'=>'读取数据失败'];
        }
        $data->toArray();
        $token=['id'=>$data['id'],'token'=>$data['token'],'expires_in'=>$data['expires_in'],'last_get_time'=>$data['last_get_time']];
        $invoicer=[
            "name" => [
                "given_name" => $data['invoicer_given_name'],
                "surname" => $data['invoicer_surname'],
            ],
            "address" => [
                "address_line_1" => $data['address_line_1'],
                "address_line_2" => $data['address_line_2'],
                "admin_area_2" => $data['admin_area_2'],
                "admin_area_1" => $data['admin_area_1'],
                "postal_code" => $data['postal_code'],
                "country_code" => $data['country_code']
            ],
            "email_address" => $data['email_address'],
            "phones" => [
                [
                    "country_code" => $data['phone_code'],
                    "national_number" => $data['phones'],
                    "phone_type" => "MOBILE"
                ]
            ],
            "website" => "",
            "tax_id" => "",
            "logo_url" => "",
            "additional_notes" => ""
        ];
        $secret_user=['client_id'=>$data['client_id'],'secret'=>$data['secret']];
        return ['status'=>true,'result'=>['token'=>$token,'invoicer'=>$invoicer,'secret_user'=>$secret_user]];

    }

}